/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aybolit.core.objects;

import aybolit.core.objects.dao.AnalyzysNameDao;
import aybolit.core.objects.dao.HealthAnalysysDao;
import aybolit.core.objects.dao.HealthingDao;
import aybolit.core.objects.model.AnalyzesName;
import aybolit.core.objects.model.Healing;
import aybolit.core.objects.model.HealingAnalyzes;
import java.io.Serializable;
import java.util.*;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Masumov Emin
 */
public class Obsledovanie implements Serializable {

    AnalyzysNameDao analysysName;
    HealthAnalysysDao healthAnalysysDao;
    private List<HealingAnalyzes> health;
    private Map<String, String> analyzesNameMap = new HashMap<String, String>();
    private String analyzesNameID;
    private Date data;
    HealthingDao healthingDaoImp;

    public List<HealingAnalyzes> healthingAnalysysByPacientId() {
        HttpSession ses = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        String id = (String) ses.getAttribute("pacientID");
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!! pacient ID" + id);
        health = healthAnalysysDao.findHealingAnalyzesByPacientId(id);
        return health;
    }

    public Map<String, String> getAnalyzes() {


        List<AnalyzesName> list = analysysName.findAllAnalyzesName();
        for (Iterator iter = list.iterator(); iter.hasNext();) {
            AnalyzesName analyzes = (AnalyzesName) iter.next();
            analyzesNameMap.put(analyzes.getName(), String.valueOf(analyzes.getAnalyzesNameId()));
        }
        return analyzesNameMap;
    }

    public void save() {
        HealingAnalyzes h = new HealingAnalyzes();
        HttpSession ses = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
        String id = (String) ses.getAttribute("pacientID");
        Healing heal = healthingDaoImp.findHellingByPacientId(id);

        h.setAnalyzesNameId(Integer.parseInt(analyzesNameID));
        h.setStatus(0);
        java.sql.Timestamp t = new java.sql.Timestamp(data.getTime());
        h.setTimestamp(t);
        h.setHealingId(heal.getHealingId());
        healthAnalysysDao.saveHealingAnalyz(h);
    }

    public HealthAnalysysDao getHealthAnalysysDao() {
        return healthAnalysysDao;
    }

    public void setHealthAnalysysDao(HealthAnalysysDao healthAnalysysDao) {
        this.healthAnalysysDao = healthAnalysysDao;
    }

    public List<HealingAnalyzes> getHealth() {
        return health;
    }

    public void setHealth(List<HealingAnalyzes> health) {
        this.health = health;
    }

    public AnalyzysNameDao getAnalysysName() {
        return analysysName;
    }

    public void setAnalysysName(AnalyzysNameDao analysysName) {
        this.analysysName = analysysName;
    }

    public Map<String, String> getAnalyzesNameMap() {
        return analyzesNameMap;
    }

    public void setAnalyzesNameMap(Map<String, String> analyzesNameMap) {
        this.analyzesNameMap = analyzesNameMap;
    }

    public String getAnalyzesNameID() {
        return analyzesNameID;
    }

    public void setAnalyzesNameID(String analyzesNameID) {
        this.analyzesNameID = analyzesNameID;
    }

    public Date getData() {
        return data;
    }

    public void setData(Date data) {
        this.data = data;
    }

    public HealthingDao getHealthingDaoImp() {
        return healthingDaoImp;
    }

    public void setHealthingDaoImp(HealthingDao healthingDaoImp) {
        this.healthingDaoImp = healthingDaoImp;
    }
}
